package com.lihui.字符串转整数;

import java.util.*;
public class Solution {
    public  static int StrToInt(String str){
        if(null==str||str.length()<1){
            return 0;
        }
        boolean negativeFlag=false;
        char[]charArray=str.toCharArray();
        if(charArray[0] == '-'){
            negativeFlag=true;
        }
        int sum=0;
        for(int i=0;i<charArray.length;++i){
            if(i==0 && charArray[i]=='+'||charArray[i]=='-'){
                continue;
            }
            if(charArray[i]<'0'||charArray[i]>'9'){
                return 0;
            }
            sum=sum *10 + (charArray[i]-'0');
        }
        return negativeFlag?(0-sum):sum;
    }

    public static void main(String[] args) {
        System.out.println();
    }
}